package core

import (
	"github.com/gomodule/redigo/redis"
)

var (
	defaultFilterName = "spider_filter_set"
)

type Filter struct {
	Name      string
	redisConn redis.Conn
}

func NewFilter(name string) *Filter {
	//f := &Filter{}
	//redisStore := store.MakeStore("redis")
	//if conn, ok := redisStore.GetConn().(redis.Conn); ok {
	//	f.Name = name
	//	f.redisConn = conn
	//	return f
	//}
	return nil
}

func (f *Filter) exists(url string) bool {
	reply, err := f.redisConn.Do("SISMEMBER", f.Name, url)
	if err != nil {
		return true
	}
	if reply.(int64) == 0 {
		if _, err := f.redisConn.Do("SADD", f.Name, url); err != nil {
			return true;
		}
		return false
	}
	return true
}
